package itpenguin;

import itpenguin.common.Util;
import itpenguin.entities.Content;
import itpenguin.entities.Series;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Series control
 * @author hiro
 *
 */
public class CrecheServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		Series series = Util.GetSeries(Util.GetKey(req)[0]);
		if (series == null) {
			resp.sendError(HttpServletResponse.SC_NOT_FOUND);
			return ;
		}
		forwardToJsp(req, resp, series);
	}

	protected void forwardToJsp(HttpServletRequest req, HttpServletResponse resp,
			Content c) throws ServletException, IOException {
		req.setAttribute("article", c);
		
		resp.addDateHeader("Last-Modified", c.getLastModified().getTime());
		
		RequestDispatcher rd = req.getRequestDispatcher("/WEB-INF/template/main.jsp");
		rd.forward(req, resp);
	}

}
